home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 February: Tool Chest / Dev.CD Feb 94.toast / New System Software Extensions / QuickDraw™ GX v1.0ß2 / Interfaces & Libraries / interfaces / math routines.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-29  |  5.1 KB  |  106 lines  |  [TEXT/MPS ]

  1. /* graphics:
  2.     math routines
  3.     by Cary Clark, Georgiann Delaney, Michael Fairman, Dave Good, Robert Johnson, Keith McGreggor, Oliver Steele, David Van Brink, Chris Yerga
  4.     Copyright 1987 - 1991 Apple Computer, Inc.  All rights reserved.    */
  5.  
  6. #ifndef mathRoutinesIncludes
  7.     #define mathRoutinesIncludes
  8.  
  9.     #ifndef mathTypesIncludes
  10.         #include "math types.h"
  11.     #endif
  12.  
  13.     #ifdef appleInternal
  14.         #define GXInlineCode(x)
  15.     #endif
  16.     #ifndef GXInlineCode
  17.         #define GXInlineCode(x)   = {0x303C, x, 0xA832}
  18.     #endif
  19.  
  20.     #ifdef __cplusplus
  21.     extern "C" {
  22.     #endif
  23.  
  24.     gxMapping *CopyToMapping(gxMapping *target, const gxMapping *source) GXInlineCode(0x2013);
  25.     gxMapping *InvertMapping(gxMapping *target, const gxMapping *source) GXInlineCode(0x2014);
  26.     gxMapping *MapMapping(gxMapping *target, const gxMapping *source) GXInlineCode(0x2015);
  27.     gxMapping *MoveMapping(gxMapping *target, fixed hOffset, fixed vOffset) GXInlineCode(0x2016);
  28.     gxMapping *MoveMappingTo(gxMapping *target, fixed hPosition, fixed vPosition) GXInlineCode(0x2017);
  29.     gxMapping *NormalizeMapping(gxMapping *target) GXInlineCode(0x2018);
  30.     gxMapping *RotateMapping(gxMapping *target, fixed angle, fixed xCenter, fixed yCenter) GXInlineCode(0x2019);
  31.     gxMapping *ScaleMapping(gxMapping *target, fixed hFactor, fixed vFactor, fixed xCenter, fixed yCenter) GXInlineCode(0x201A);
  32.     gxMapping *ResetMapping(gxMapping *target) GXInlineCode(0x201B);
  33.     gxMapping *SkewMapping(gxMapping *target, fixed skewX, fixed skewY, fixed xCenter, fixed yCenter) GXInlineCode(0x201C);
  34.  
  35.     void MapPoints(const gxMapping *source, long count, gxPoint vector[]) GXInlineCode(0x201D);
  36.  
  37.     short FirstBit(unsigned long) GXInlineCode(0x201E);
  38.     short WideScale(const gxWide *source) GXInlineCode(0x201F);
  39.  
  40.     short LinearRoot(fixed first, fixed last, fract t[]) GXInlineCode(0x2020);
  41.     short QuadraticRoot(fixed first, fixed control, fixed last, fract t[]) GXInlineCode(0x2021);
  42.  
  43.     gxPoint *PolarToPoint(const gxPolar *, gxPoint *) GXInlineCode(0x2022);
  44.     gxPolar *PointToPolar(const gxPoint *, gxPolar *) GXInlineCode(0x2023);
  45.  
  46.     fract FractCubeRoot(fract source) GXInlineCode(0x2024);
  47.     fract FractDivide(fract dividend, fract divisor) GXInlineCode(0x2025);
  48.     fract FractMultiply(fract multiplicand, fract multiplier) GXInlineCode(0x2026);
  49.     fract FractSineCosine(fixed degrees, fract *cosine) GXInlineCode(0x2027);
  50.     fract FractSquareRoot(fract source) GXInlineCode(0x2028);
  51.  
  52.     fixed FixedDivide(fixed dividend, fixed divisor) GXInlineCode(0x2029);
  53.     fixed FixedMultiply(fixed multiplicand, fixed multiplier) GXInlineCode(0x202A);
  54.  
  55.     /* This next call is (source * multiplier / divisor) -- it avoids underflow, overflow by using wides */
  56.     long MultiplyDivide(long source, long multiplier, long divisor) GXInlineCode(0x202B);
  57.  
  58.     unsigned long Magnitude(long deltaX, long deltaY) GXInlineCode(0x202C);
  59.     long VectorMultiplyDivide(long count, const long *vector1, long step1, const long *vector2, long step2, long divisor) GXInlineCode(0x202D);
  60.  
  61.     gxWide *WideAdd(gxWide *target, const gxWide *source) GXInlineCode(0x202E);
  62.     short WideCompare(const gxWide *target, const gxWide *source) GXInlineCode(0x202F);
  63.     gxWide *WideNegate(gxWide *target) GXInlineCode(0x2030);
  64.     gxWide *WideShift(gxWide *target, long shift) GXInlineCode(0x2031);
  65.     unsigned long WideSquareRoot(const gxWide *source) GXInlineCode(0x2032);
  66.     gxWide *WideSubtract(gxWide *target, const gxWide *source) GXInlineCode(0x2033);
  67.  
  68.     gxWide *WideMultiply(long multiplicand, long multiplier, gxWide *target) GXInlineCode(0x2034);
  69.     long WideDivide(const gxWide *dividend, long divisor, long *remainder) GXInlineCode(0x2035);        /* returns the quotient */
  70.     gxWide *VectorMultiply(long count, const long *vector1, long step1, const long *vector2, long step2, gxWide *dot) GXInlineCode(0x2036);
  71.     gxWide *WideWideDivide(gxWide *dividend, long divisor, long *remainder) GXInlineCode(0x203B);    /* quotient replaces dividend */
  72.  
  73.     unsigned long RandomBits(long count, long focus) GXInlineCode(0x2037);
  74.     void SetRandomSeed(const gxWide *seed) GXInlineCode(0x2038);
  75.     gxWide *GetRandomSeed(gxWide *seed) GXInlineCode(0x2039);
  76.  
  77.     #ifdef __cplusplus
  78.     }
  79.     #endif
  80.  
  81.     #undef GXInlineCode
  82.  
  83.     #define FixedRound(a)       ((short)((fixed)(a) + fixed1/2 >> 16))
  84.     #define FixedSquareRoot(a)  ((fixed)FractSquareRoot(a) + 64 >> 7)
  85.     #define FixedTruncate(a)        ((short)((fixed)(a) >> 16))
  86.  
  87.     #define FixedToFract(a)     ((fract)(a) << 14)
  88.     #define FractToFixed(a)     ((fixed)(a) + 8192L >> 14)
  89.  
  90.     #define FixedToInt(a)       ((short)((fixed)(a) + fixed1/2 >> 16))
  91.     #define IntToFixed(a)       ((fixed)(a) << 16)
  92.  
  93.     #define FixedToFloat(a)     ((float)(a) / fixed1)
  94.     #define FloatToFixed(a)         ((fixed)((float)(a) * fixed1))
  95.  
  96.     #define FractToFloat(a)     ((float)(a) / fract1)
  97.     #define FloatToFract(a)     ((fract)((float)(a) * fract1))
  98.  
  99.     #define ColorToFract(a)     (((fract) (a) << 14) + ((fract)(a) + 2 >> 2))
  100.     #define FractToColor(a)     ((gxColorValue) ((a) - ((a) >> 16) + 8191 >> 14))
  101.  
  102.     #define ff(a)               IntToFixed(a)
  103.     #define fl(a)               FloatToFixed(a)
  104.  
  105. #endif
  106.